package com.itWaiLong.Controller.User;


import com.itWaiLong.Dao.project_share;
import com.itWaiLong.Result.Result;
import com.itWaiLong.Service.ShareProjectService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/share")
public class UserShareProjectController {

    @Autowired
    private ShareProjectService shareProjectService;

    /**
     * 用户分享自己的项目
     * @return
     */
    @PostMapping("/userShare")
    public Result share(@RequestBody project_share projectShare){
        log.info("分享的项目的信息：{}",projectShare);

        shareProjectService.share(projectShare);
        return Result.success();
    }

    /**
     * 删除分享的项目
     * @param projectId
     * @return
     */
    @GetMapping("/delete")
    public Result delete(@RequestParam int projectId){
        shareProjectService.delete(projectId);
        return Result.success();
    }

    /**
     * 用户浏览分享页
     * @return
     */
    @GetMapping("/browse")
    public Result<List<project_share>> getUserShare(){

        return Result.success(shareProjectService.browse());
    }
}
